package com.yaorange.ma_util.util;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;

import java.util.Date;
import java.util.Map;

public class JwtUtil {
    private static final String KEY = "violetSnow";
    public static String generateToken(Map<String, Object> claims) {
        return JWT.create()
                .withClaim("claim",claims)
                .withExpiresAt(new Date(System.currentTimeMillis()*1000*60*60*12))
                .sign(Algorithm.HMAC256(KEY));

    }

    public static Map<String, Object> parseToken(String token) {
        return JWT.require(Algorithm.HMAC256(KEY))
                .build()
                .verify(token)
                .getClaim("claim")
                .asMap();
    }
}
